function StartTimer(time)
{
	if (time > 0)
	{
		$('#timer').replaceWith('<span style="text-align:justify;" id="timer">' + time + ' seconds left</span>');
		countdown = window.setTimeout(function() { StartTimer(time-1); },1000);
		timerStarted = true;
	}
	else
	{
		$('#timer').replaceWith('<span style="text-align:justify;" id="timer">Countdown finished</span>');
		clearTimeout(countdown);
		timerStarted = false;
	}
}

function ShowTask()
{
	var randomTask = getRandomInt(0, 9);
	countdownTimer = getRandomInt(1, 10) * 60;
	$('#timer').replaceWith('<span style="text-align:justify;" id="timer">' + countdownTimer + ' seconds left</span>');
	UpdateRacialBonus();
	$('#taskItems').replaceWith('<span style="text-align:justify;" id="taskItems">(To solve with: <u>' + itemsToUse[WebPlayer.position-1] + '</u>)</span>');
	
	if (WebPlayer.position === 1 && randomTask === 9) // gnome task 9
	{
		var tempTask = tasks[WebPlayer.position-1][randomTask];
		var roll1 = getRandomInt(0, 9);
		var roll2 = getRandomInt(0, 9);
		var roll3 = getRandomInt(0, 9);
		tempTask = tempTask.replace(/@X@/, roll1);
		tempTask = tempTask.replace(/@Y@/, roll2);
		tempTask = tempTask.replace(/@Z@/, roll3);
		$('#taskDesc').replaceWith('<span style="text-align:justify;" id="taskDesc">' + tempTask + '</span>');
	}
	else if (WebPlayer.position === 4 && randomTask === 3) // goblin task 3
	{
		var tempTask = tasks[WebPlayer.position-1][randomTask];
		var roll = getRandomInt(0, 9);
		tempTask = tempTask.recplace("@H@", roll);
	}
	else if (WebPlayer.position === 3 && randomTask === 9) // orcs task 9
	{
		var tempTask = tasks[WebPlayer.position-1][randomTask];
		var roll = getRandomInt(0, 9);
		if (roll % 2 != 0)
		{
			tempTask = "<b>First fuck: </b>" + tempTask + "<br><b>Second fuck: </b>" + tasks[WebPlayer.position-1][roll];  
		}
		$('#taskDesc').replaceWith('<span style="text-align:justify;" id="taskDesc">' + tempTask + '</span>');
	}
	else if (WebPlayer.position === 4) // goblin tasks 
	{
		var tempTask = tasks[gameParams[3]-1][randomTask];
		var roll = getRandomInt(0, 9);
		tempTask = tempTask.replace(/@G@/, roll);
		$('#taskDesc').replaceWith('<span style="text-align:justify;" id="taskDesc">' + tempTask + '</span>');
	}
	else if (WebPlayer.position === 5 && randomTask === 9) // elves task 9
	{
		var tempTask = tasks[WebPlayer.position-1][randomTask];
		var roll = getRandomInt(0, 9);
		tempTask = "<b>First fuck: </b>" + tempTask + "<br><b>Second fuck: </b>" + tasks[WebPlayer.position-1][roll];
		$('#taskDesc').replaceWith('<span style="text-align:justify;" id="taskDesc">' + tempTask + '</span>');
	}
	else if (WebPlayer.position === 8 && randomTask === 9) // human task 9
	{
		var tempTask = tasks[WebPlayer.position-1][randomTask];
		var roll = getRandomInt(1, 30);
		tempTask = tempTask.replace(/@X@/, roll);
		$('#taskDesc').replaceWith('<span style="text-align:justify;" id="taskDesc">' + tempTask + '</span>');
	}
	else if (WebPlayer.position === 9) // minotaur tasks
	{
		var tempTask = tasks[WebPlayer.position-1][randomTask];
		var roll = getRandomInt(1, 9);
		if (randomTask === 0)
		{
			roll = roll * 10;
		}
		else if (randomTask === 5)
		{
			roll = Math.ceil(roll / 2);
		}
		tempTask = tempTask.replace(/@X@/, roll);
		$('#taskDesc').replaceWith('<span style="text-align:justify;" id="taskDesc">' + tempTask + '</span>');
	}
	else // default task
	{
		$('#taskDesc').replaceWith('<span style="text-align:justify;" id="taskDesc">' + tasks[WebPlayer.position-1][randomTask] + '</span>');
	}
	$('#taskPannel').css("display", "block");
	$('#grayLayer').css("display", "block");
}

function TaskFinished()
{
	if (gameRunning)
	{
		clearTimeout(countdown);
		timerStarted = false;
		WebPlayer.levelUp();	// add 1 level and 1 gold piece
		$('#taskPannel').css("display", "");
		$('#grayLayer').css("display", "");
		UpdatePosition();
		UpdateGoldPieces();
		UpdateLevel();
	}
}